

fname='C:\tmpdata\augentest\AugenTest0006';

[idata2,aux2]=load_eye_monitor_data([fname '_2.eye'],1);
[idata3,aux3]=load_eye_monitor_data([fname '_3.eye'],1);

found_aux_data=1;
try
    aux_data=load_lvd([fname '.lvd']);
    [velP,velM,velP_ind,velM_ind,velP_raw,velM_raw]=get_vel_ind_from_adata(aux_data);
    iframe_times2=get_iframe_times(aux2,aux_data(4,:));
    iframe_times3=get_iframe_times(aux3,aux_data(4,:));
catch
    found_aux_data=0;
end

ift2=aux2(1,:);
ift2(1)=0;

ift3=aux3(1,:);
ift3(1)=0;

map_ind=[];

if length(ift3)<length(ift2)
    for ind=1:length(ift3)
        [~,map_ind(ind)]=min(abs(ift3(ind)-ift2));
    end
    ift2=ift2(map_ind);
    iframe_times2=iframe_times2(map_ind);
    idata2=idata2(:,:,map_ind);
elseif length(ift3)>length(ift2)
    for ind=1:length(ift2)
        [~,map_ind(ind)]=min(abs(ift2(ind)-ift3));
    end
    ift3=ift3(map_ind);
    iframe_times3=iframe_times3(map_ind);
    idata3=idata3(:,:,map_ind);
end

if size(idata3,1)<size(idata2,1)
    idata2=idata2(1:size(idata3,1),:,:);
elseif size(idata3,1)>size(idata2,1)
    idata3=idata3(1:size(idata2,1),:,:);
end

if size(idata3,2)<size(idata2,2)
    idata2=idata2(:,1:size(idata3,2),:);
elseif size(idata3,2)>size(idata2,2)
    idata3=idata3(:,1:size(idata2,2),:);
end

running_speed=-velP(iframe_times2)';
running_speed(running_speed<0)=0;

if found_aux_data
    view_tiff_stack_plot_aux([permute(idata2,[2 1 3]),permute(idata3,[2 1 3])],running_speed);
else
    view_tiff_stack([permute(idata2,[2 1 3]),permute(idata3,[2 1 3])]);
end




[saccade_frames2, pupil_diam2, pupil_pos2] = find_saccades(idata2);
[saccade_frames3, pupil_diam3, pupil_pos3] = find_saccades(idata3);
figure;
subplot(211);
hold on
plot(iframe_times2/1000,pupil_pos2(1,:))
plot(iframe_times2/1000,pupil_pos3(1,:),'r')
xlim([0 iframe_times2(end)/1000])
xlabel('Time [s]')

subplot(212);
hold on
plot(iframe_times2/1000,pupil_diam2)
plot(iframe_times2/1000,pupil_diam3,'r')
xlim([0 iframe_times2(end)/1000])
xlabel('Time [s]')













